home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
kermit.columbia.edu
/
kermit.columbia.edu.tar
/
kermit.columbia.edu
/
newsgroups
/
misc.19981211-19990422
/
000427_news@watsun.cc.columbia.edu _Wed Mar 31 11:20:37 1999.msg
< prev
next >
Wrap
Internet Message Format
|
1999-04-21
|
3KB
Return-Path: <news@watsun.cc.columbia.edu>
Received: from newsmaster.cc.columbia.edu (newsmaster.cc.columbia.edu [128.59.59.30])
by watsun.cc.columbia.edu (8.8.5/8.8.5) with ESMTP id LAA21243
for <kermit.misc@watsun.cc.columbia.edu>; Wed, 31 Mar 1999 11:20:36 -0500 (EST)
Received: (from news@localhost)
by newsmaster.cc.columbia.edu (8.8.5/8.8.5) id KAA13731
for kermit.misc@watsun.cc.columbia.edu; Wed, 31 Mar 1999 10:59:01 -0500 (EST)
X-Authentication-Warning: newsmaster.cc.columbia.edu: news set sender to <news> using -f
From: dn5006@my-dejanews.com
Subject: SWITCH statement considered harmful
Date: Wed, 31 Mar 1999 15:09:20 GMT
Organization: Deja News - The Leader in Internet Discussion
Message-ID: <7dtdqo$tg8$1@nnrp1.dejanews.com>
To: kermit.misc@watsun.cc.columbia.edu
; In languages such as Kermit script, Tcl script, C, etc. , the switch
; statement could be the source of subtle bugs caused by the intentional or
; unintentional omission of the break statement.
;
; 'Using C-Kermit' 2nd, page 385, displays a classical usage of the switch
; statement with the intentional omission of the break statement to achieve a
; "fall-through".
; This programming way is error prone and should be avoided.
;
; Consider the following alternative which is more defensive and maintenance
; friendly, since:
; 1. New cases if any can be added easily.
; 2. No break statement is needed to terminate a case.
; 3. Fall through is explicit through the specification of the targeted case,
; which can be any of the possible cases, even backward, skip intermitten
; cases, whatever.
; 4. Each case label is expressive.
; 5. Default statement is replaced with the check on fail.
; 6. No subtle bugs caused by the implementation of the switch statemnet.
;
; Kermit scripting language is not C. When programming in Kermit, use Kermit
; idioms, don't mimic C.
define weekday {
local day_0 day_1 day_2 day_3 day_4 day_5 day_6
define day_0 { echo Sonntag }
define day_1 { echo Montag und uebermorgen ist, day_3 }
define day_2 { echo Dienstag und zunaechst kommt ..., day_3 }
define day_3 { echo Mittwoch }
define day_4 { echo Donnerstag }
define day_5 { echo Freitag und gestern war, day_4}
define day_6 { echo Samstag und da ist schon wieder der, day_0}
day_\v(nday)
if fail echo Invalid day - \v(nday)
}
; This is object-oriented programming in the small, the day_ is generic, when
; appended with a case specific value, it yields the name of a predefined
macro, ; and get executed. This flexibility is very effective.
Dat Nguyen
Airline Telecommunications and Information Services
770 Sherbrooke West
Montreal, Quebec
Canada H3A 1G1
Email dat.nguyen&sita.int
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own